package org.rsbot.script.methods;

import org.rsbot.client.Cache;
import org.rsbot.client.DefLoader;
import org.rsbot.client.HashTable;
import org.rsbot.client.Node;

public class Nodes extends MethodProvider
{
  Nodes(MethodContext paramMethodContext)
  {
    super(paramMethodContext);
  }

  public Node lookup(HashTable paramHashTable, long paramLong)
  {
    try
    {
      if ((paramHashTable == null) || (paramHashTable.getBuckets() == null) || (paramLong < 0L)) {
        return null;
      }
      Node localNode1 = paramHashTable.getBuckets()[(int)(paramLong & paramHashTable.getBuckets().length - 1)];
      for (Node localNode2 = localNode1.getPrevious(); localNode2 != localNode1; localNode2 = localNode2.getPrevious())
      {
        if (localNode2.getID() == paramLong)
          return localNode2;
      }
    } catch (Exception localException) {
    }
    return null;
  }

  public Node lookup(DefLoader paramDefLoader, long paramLong)
  {
    if ((paramDefLoader == null) || (paramDefLoader.getCache() == null)) {
      return null;
    }
    return lookup(paramDefLoader.getCache().getTable(), paramLong);
  }
}